{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# 归一化 Normallization\n",
    "\n",
    "## 为什么要进行数值归一化？\n",
    "> 下面是肿瘤预测数据的表格，可以看出发现时间和肿瘤大小两个参数的数值不是一个量级，会导致kNN中的样本间的距离被发现时间所主导，这样是明显有失偏颇地\n",
    "![数值归一化必要性的例子](images/数值归一化必要性的例子.png)\n",
    "\n",
    "## 数据归一化的原理\n",
    "\n",
    "> 将所有的数据映射到同一尺度\n",
    "\n",
    "## 数据归一化最常用的方案:最值归一化\n",
    "\n",
    "> 最值归一化：把所有的数据映射到0-1之间  \n",
    "![数值归一化最常用方案之最值归一化](images/数值归一化最常用方案之最值归一化.png)  \n",
    "最值归一化适用于有明显分界的情况，受outlier(`翻译为极端值、离群值或逸出值`)影响较大。比如收入调查样本中，如果100个人中有一个人是个亿万富翁，其他人都是穷光蛋，那么用最值归一化时其他的人都可以忽略不计了，这是不合理的，即受到了outlier的影响。所以有了更为合理的归一化方案：均值方差归一化 standardization\n",
    "\n",
    "### 均值方差归一化 standardization\n",
    "> 把所有的数据归一到均值为0方差为1的分布中。适用于数据分布没有明显的边界，而且有可能存在极端数据值的情况\n",
    "![均值方差归一化](images/均值方差归一化.png)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 下面是一维数组的归一化，简单点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.random.randint(0, 100, size=100) # 100个0~100的随机整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([58, 19, 66, 40, 28, 26, 11, 49, 52, 58,  0, 57,  1, 88, 35, 25, 88,\n",
       "       57, 57, 87,  6, 35, 63,  6, 82, 72, 27, 20, 66, 38, 48, 29, 83, 27,\n",
       "       85, 21, 90, 62,  4, 73, 11, 76, 12, 81, 16, 76, 33,  3, 89, 10, 42,\n",
       "       92,  3, 12,  1, 25, 45, 78, 35, 37, 63, 98, 19, 86, 95, 87, 46, 97,\n",
       "       75, 18, 81, 12, 56, 33, 36, 69, 95, 23, 23, 21, 34, 74, 64, 97, 31,\n",
       "       31,  6, 70, 69, 69, 13, 82, 86, 22, 68, 79, 82, 49, 88, 56])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.59183673, 0.19387755, 0.67346939, 0.40816327, 0.28571429,\n",
       "       0.26530612, 0.1122449 , 0.5       , 0.53061224, 0.59183673,\n",
       "       0.        , 0.58163265, 0.01020408, 0.89795918, 0.35714286,\n",
       "       0.25510204, 0.89795918, 0.58163265, 0.58163265, 0.8877551 ,\n",
       "       0.06122449, 0.35714286, 0.64285714, 0.06122449, 0.83673469,\n",
       "       0.73469388, 0.2755102 , 0.20408163, 0.67346939, 0.3877551 ,\n",
       "       0.48979592, 0.29591837, 0.84693878, 0.2755102 , 0.86734694,\n",
       "       0.21428571, 0.91836735, 0.63265306, 0.04081633, 0.74489796,\n",
       "       0.1122449 , 0.7755102 , 0.12244898, 0.82653061, 0.16326531,\n",
       "       0.7755102 , 0.33673469, 0.03061224, 0.90816327, 0.10204082,\n",
       "       0.42857143, 0.93877551, 0.03061224, 0.12244898, 0.01020408,\n",
       "       0.25510204, 0.45918367, 0.79591837, 0.35714286, 0.37755102,\n",
       "       0.64285714, 1.        , 0.19387755, 0.87755102, 0.96938776,\n",
       "       0.8877551 , 0.46938776, 0.98979592, 0.76530612, 0.18367347,\n",
       "       0.82653061, 0.12244898, 0.57142857, 0.33673469, 0.36734694,\n",
       "       0.70408163, 0.96938776, 0.23469388, 0.23469388, 0.21428571,\n",
       "       0.34693878, 0.75510204, 0.65306122, 0.98979592, 0.31632653,\n",
       "       0.31632653, 0.06122449, 0.71428571, 0.70408163, 0.70408163,\n",
       "       0.13265306, 0.83673469, 0.87755102, 0.2244898 , 0.69387755,\n",
       "       0.80612245, 0.83673469, 0.5       , 0.89795918, 0.57142857])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x - np.min(x)) / (np.max(x) - np.min(x)) # 最值归一化：将x的所有元素都进行了归一化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 下面是二维数组的归一化，对每一列进行归一化即可"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "X= np.random.randint(0, 100, (50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[18, 97],\n",
       "       [ 9, 30],\n",
       "       [67, 30],\n",
       "       [92, 25],\n",
       "       [82, 71],\n",
       "       [70,  3],\n",
       "       [56,  9],\n",
       "       [89, 11],\n",
       "       [73, 82],\n",
       "       [58, 17]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10] # 取出前10个数看下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[18, 97],\n",
       "       [ 9, 30],\n",
       "       [67, 30],\n",
       "       [92, 25],\n",
       "       [82, 71],\n",
       "       [70,  3],\n",
       "       [56,  9],\n",
       "       [89, 11],\n",
       "       [73, 82],\n",
       "       [58, 17]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10, :] # 取出x的前10行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.array(X, dtype=float) # 因为要归一化到0~1，所以数据类型要转换到浮点型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 下面是对每列进行最值归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "X[:, 0] = (X[:, 0] - np.min(X[:, 0])) / (np.max(X[:, 0]) - np.min(X[:, 0])) # 第一列归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "X[:, 1] = (X[:, 1] - np.min(X[:, 1])) / (np.max(X[:, 1]) - np.min(X[:, 1])) # 第二列归一化。n列的话注意要循环一下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.18367347, 0.97938144],\n",
       "       [0.09183673, 0.28865979],\n",
       "       [0.68367347, 0.28865979],\n",
       "       [0.93877551, 0.2371134 ],\n",
       "       [0.83673469, 0.71134021],\n",
       "       [0.71428571, 0.01030928],\n",
       "       [0.57142857, 0.07216495],\n",
       "       [0.90816327, 0.09278351],\n",
       "       [0.74489796, 0.82474227],\n",
       "       [0.59183673, 0.15463918]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAVrklEQVR4nO3dbYxcV3nA8f+DQ2BbKFthI5G1g41qUiIi1WiU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Dwkf7fnwJeHBExxTbWZWhfM/OLmfnT/s076W3c3VZVPluAtwPvBH42zcZNQJX+vha4OTN/ApCZD0y5jXWq0t8Efq3/99M4fxP61sjML9PbhnMzh4GPZs+dwGJEPLOu129LQF8C7lt3e6V/38BjMvNR4CHg6VNpXb2q9HW96+j9H7+thvY3Ig4AezLzs9Ns2IRU+XyfAzwnIr4SEXdGxKGpta5+Vfr7NuBVEbFCb6vLN06naTMx6vd7JJX2FG2AQSPtjfWWVY5pg8r9iIhXAR3g9ybaosnasr8R8QTgPcAfT6tBE1bl872AXtrlhfR+ff17RDwvMx+ccNsmoUp/rwU+nJnvjojfobfh/PMy8/8m37ypm2icassIfQXYs+72bs7/WfaLYyLiAno/3bb66dNUVfpKRLwEeAtwVWb+fEptm4Rh/X0q8DzgSxHxPXp5x+UWXxitei5/JjMfyczvAvfQC/BtVKW/1wG3AWTmV4En01vIqkSVvt/b1ZaAfgrYHxH7IuJCehc9lzccswy8pv/3y4GT2b8K0TJD+9pPQXyQXjBvc34VhvQ3Mx/KzJ2ZuTcz99K7ZnBVZnZn09yxVTmXT9C78E1E7KSXgrl3qq2sT5X+/gB4MUBEPJdeQF+baiunZxl4db/a5QXAQ5n5w9qefdZXhUe4enwl8N/0rpi/pX/fjfS+3NA7CT4JnAH+A3j2rNs8wb7+K/C/wNf7/5Zn3eZJ9nfDsV+ixVUuFT/fAP4euBv4FnBk1m2ecH8vBb5CrwLm68AfzLrNY/T148APgUfojcavA14HvG7dZ3tz/734Vt3nslP/JakQbUm5SJKGMKBLUiEM6JJUCAO6JBXCgC5JhTCgS1IhDOiSVIj/B6B5lvJdC/seAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:, 0], X[:, 1])\n",
    "plt.show()\n",
    "# 从下面图中可以看到所有的点都被归一到0~1范围内了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5293877551020408"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X[:, 0]) # 接近0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.29875933936388144"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X[:, 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4288659793814433"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X[:, 1]) # 接近0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2943691634305235"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X[:, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(X[:, 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(X[:, 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(X[:, 1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(X[:, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 均值方差归一化 Standardization\n",
    "> ![均值方差归一化](images/均值方差归一化.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.random.randint(0, 100, (50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.array(X2, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2[:, 0] = (X2[:, 0] - np.mean(X2[:, 0])) / np.std(X2[:, 0])  # 第一列的均值方差归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2[:, 1] = (X2[:, 1] - np.mean(X2[:, 1])) / np.std(X2[:, 1])  # 第二列的均值方差归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAXvElEQVR4nO3df4xdZZ3H8fdnC+LEGAu0/OjA0KJYqaJWJvVHExdBLVRDK0gW/EPY1TTuLtnEzTYZQqIbEkNdkt2swq5WlgjJLuAilCp1K1gNG3ZxmVqwIFTKD0NniBTY4prtKq3f/eOekWl77507c84959zzfF7JZO499/SeZ86d+f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Y2H5b7vpDWmlh1txn4dFat8z7glam0YF1JOmlqPEfSClrx+aXu/2qWqh65HtQv4BO0ehG/AX4JbM22LwK2ZI9Pp1X18AjwGK20Sq3bnD1fTWuF06eqbnPWnuOBHwBPZt+Py7aPAjdmjz8A7MzO9U7gMxW19YhzB1wDXJg9fj3wr8Bu4L+A02twfmdq87XZ7+8jwA+Bt9WgzbcCzwOvZr/TnwE+B3wue120bq36VPb70LGSrkZtvnLaeX4Q+EDRbfDSCmZmiXBKx8wsEQ74ZmaJcMA3M0uEA76ZWSIc8M3MEuGAb2aWCAd8M7NE/D8NSY2S6iIYUQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:, 0], X2[:, 1])\n",
    "plt.show()\n",
    "# 下面图可以看到均值方差归一化并不能让样本的值限制在0~1之间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.9968028886505634e-17"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X2[:, 0]) # 无限逼近0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X2[:, 0]) # 无限逼近1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.549516567451065e-17"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X2[:, 1]) # 无限逼近0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9999999999999999"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X2[:, 1]) # 无限逼近1，或者就是1.满足均值是0，方差是1的均值方差归一化的条件"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
